﻿Imports System.IO
Public Class frmTerraweather
    Private OS_ID As String = ""
    Private m_ArrConcourse As New GroundDataCommunicationConcourse
    Private m_title As New GroundDataTitle
    Private m_OpenFile As Boolean = False
    ''' <summary>
    '''   把数据显示到表格中
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ShowFlexData()
        Dim time As String
        'Me.FlexData.Clear()
        Me.FlexData.Rows.Count = Me.m_ArrConcourse.ArrGroundDataCommunication.Length + 1
        For i As Integer = 0 To Me.m_ArrConcourse.ArrGroundDataCommunication.Length - 1
            Me.FlexData.SetData(i + 1, 0, i + 1)
            time = Me.m_ArrConcourse.ArrGroundDataCommunication(i).Year & "-" & Me.m_ArrConcourse.ArrGroundDataCommunication(i).Month & "-" & Me.m_ArrConcourse.ArrGroundDataCommunication(i).Day
            Me.FlexData.SetData(i + 1, 1, time)
            Me.FlexData.SetData(i + 1, 2, Me.m_ArrConcourse.ArrGroundDataCommunication(i).CountDay)
            Me.FlexData.SetData(i + 1, 3, Me.m_ArrConcourse.ArrGroundDataCommunication(i).Time)


            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).HeatEnergy = -999 Then

            Else
                Me.FlexData.SetData(i + 1, 4, Me.m_ArrConcourse.ArrGroundDataCommunication(i).HeatEnergy)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraRubVelocity = -9 Then

            Else
                Me.FlexData.SetData(i + 1, 5, Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraRubVelocity)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).ConvectionVelocityScale = -9 Then

            Else
                Me.FlexData.SetData(i + 1, 6, Me.m_ArrConcourse.ArrGroundDataCommunication(i).ConvectionVelocityScale)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).LadderTemperature = -9 Then

            Else
                Me.FlexData.SetData(i + 1, 7, Me.m_ArrConcourse.ArrGroundDataCommunication(i).LadderTemperature)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).ConvectionBoundaryHeight = -999 Then

            Else
                Me.FlexData.SetData(i + 1, 8, Me.m_ArrConcourse.ArrGroundDataCommunication(i).ConvectionBoundaryHeight)
            End If

            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).MachineBoundaryHeight = -999 Then

            Else
                Me.FlexData.SetData(i + 1, 9, Me.m_ArrConcourse.ArrGroundDataCommunication(i).MachineBoundaryHeight)
            End If

            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).MoniLong = -99999 Then

            Else
                Me.FlexData.SetData(i + 1, 10, Me.m_ArrConcourse.ArrGroundDataCommunication(i).MoniLong)
            End If

            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraCrassitude = -9 Then

            Else
                Me.FlexData.SetData(i + 1, 11, Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraCrassitude)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraBowen = -9 Then

            Else
                Me.FlexData.SetData(i + 1, 12, Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraBowen)
            End If

            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraAlbedo = -9 Then

            Else
                Me.FlexData.SetData(i + 1, 13, Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraAlbedo)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindSpeed = -999.9 Then

            Else
                Me.FlexData.SetData(i + 1, 14, Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindSpeed)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindVane = 990 Then

            Else
                Me.FlexData.SetData(i + 1, 15, Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindVane)
            End If

            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindHeight = 0 Then
            Else
                Me.FlexData.SetData(i + 1, 16, Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindHeight)
            End If

            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).Lapse_Rate = 999 Then
            Else
                Me.FlexData.SetData(i + 1, 17, Me.m_ArrConcourse.ArrGroundDataCommunication(i).Lapse_Rate)
            End If

            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).TemperatureScaleHeight = 0 Then
            Else
                Me.FlexData.SetData(i + 1, 18, Me.m_ArrConcourse.ArrGroundDataCommunication(i).TemperatureScaleHeight)

            End If


            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).DropWaterType = 0 Then
            Else
                Me.FlexData.SetData(i + 1, 19, Me.m_ArrConcourse.ArrGroundDataCommunication(i).DropWaterType)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).DropWaterQuantity = -9 Then
            Else
                Me.FlexData.SetData(i + 1, 20, Me.m_ArrConcourse.ArrGroundDataCommunication(i).DropWaterQuantity)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).ComparativelyHumidity = 999 Then
            Else
                Me.FlexData.SetData(i + 1, 21, Me.m_ArrConcourse.ArrGroundDataCommunication(i).ComparativelyHumidity)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraPa = 99999 Then
            Else
                Me.FlexData.SetData(i + 1, 22, Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraPa)
            End If
            If Me.m_ArrConcourse.ArrGroundDataCommunication(i).LowCloudCover = 99 Then
            Else
                Me.FlexData.SetData(i + 1, 23, Me.m_ArrConcourse.ArrGroundDataCommunication(i).LowCloudCover)
            End If




        Next
        Me.FlexData.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.FlexData.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.None
        Me.FlexData.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.FlexData.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.FlexData.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.FlexData.Rows.Count = 1
        '经度

        Me.cobJd.Items.Add("E")
        Me.cobJd.Items.Add("W")
        Me.cobJd.Text = "E"

        '纬度

        Me.cobWd.Items.Add("N")
        Me.cobWd.Items.Add("S")
        Me.cobWd.Text = "N"
        Me.FlexData.AutoSizeRows()
        Me.m_OpenFile = False

        Me.FlexData.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.FlexData.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.FlexData.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None

    End Sub
   


    Private Sub FlexData_AfterEdit(ByVal sender As System.Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles FlexData.AfterEdit
        Dim Trow As Integer = Me.FlexData.RowSel
        Dim Tcol As Integer = Me.FlexData.ColSel

        If Trow > 0 Then
            If Tcol = 4 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).HeatEnergy = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 5 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).TerraRubVelocity = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 6 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).ConvectionVelocityScale = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 7 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).LadderTemperature = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 8 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).ConvectionBoundaryHeight = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 9 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).MachineBoundaryHeight = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 10 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).TerraCrassitude = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 11 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).TerraBowen = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 12 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).TerraAlbedo = Me.FlexData.GetData(Trow, Tcol)

            ElseIf Tcol = 13 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).WindSpeed = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 14 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).WindVane = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 15 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).WindHeight = Me.FlexData.GetData(Trow, Tcol)

            ElseIf Tcol = 16 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).Lapse_Rate = Me.FlexData.GetData(Trow, Tcol)
            ElseIf Tcol = 17 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).TemperatureScaleHeight = Me.FlexData.GetData(Trow, Tcol)

            ElseIf Tcol = 18 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).DropWaterType = Me.FlexData.GetData(Trow, Tcol)


            ElseIf Tcol = 19 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).DropWaterQuantity = Me.FlexData.GetData(Trow, Tcol)

            ElseIf Tcol = 20 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).ComparativelyHumidity = Me.FlexData.GetData(Trow, Tcol)


            ElseIf Tcol = 21 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).TerraPa = Me.FlexData.GetData(Trow, Tcol)

            ElseIf Tcol = 22 Then
                Me.m_ArrConcourse.ArrGroundDataCommunication(Trow - 1).LowCloudCover = Me.FlexData.GetData(Trow, Tcol)


            End If

        End If
    End Sub

    Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click

        Dim f_HeatEnergy As String = ""
        Dim f_TerraRubVelocity As String = ""
        Dim f_ConvectionVelocityScale As String = ""
        Dim f_LadderTemperature As String = ""
        Dim f_ConvectionBoundaryHeight As String = ""

        Dim f_MachineBoundaryHeight As String = ""
        Dim f_MoniLong As String = ""
        Dim f_TerraCrassitude As String = ""
        Dim f_TerraBowen As String = ""
        Dim f_TerraAlbedo As String = ""

        Dim f_WindSpeed As String = ""
        Dim f_WindVane As String = ""
        Dim f_WindHeight As String = ""
        Dim f_Lapse_Rate As String = ""
        Dim f_TemperatureScaleHeight As String = ""

        Dim f_DropWaterType As String = ""
        Dim f_DropWaterQuantity As String = ""
        Dim f_ComparativelyHumidity As String = ""
        Dim f_TerraPa As String = ""
        Dim f_LowCloudCover As String = ""


        Dim msgerror As Boolean = True
        Dim a As Integer = 0
        Dim p As Integer = 0
        Dim terra As String = "UA_ID:"
        Dim Result As DialogResult
        Dim msg As Integer = 0
        Me.OpenFileDialog1 = New OpenFileDialog()
        OpenFileDialog1.Filter = "地面气象数据文件(*.SFC)|*.SFC"
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
            Dim b As Integer = 0
            If OpenFileDialog1.FileName <> "" Then

                Do Until EOF(1)
                    Dim strline As String = LineInput(1)
                    msg += 1
                    If msg = 1 Then
                        If StringHandle.GetString(strline, 3) = terra Then
                            msgerror = True
                            Me.m_OpenFile = True


                        Else
                            msgerror = False
                            Result = MessageBox.Show("选择的文件格式不正确！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                            If Result = Windows.Forms.DialogResult.OK Then
                                Exit Do
                            End If
                        End If
                    End If



                    a += 1
                    If a = 1 Then
                        Me.m_title.Latitude = StringHandle.GetString(strline, 1)

                        Me.txtLongitude.Text = m_title.Latitude.Remove(m_title.Latitude.Length - 1)
                        If m_title.Latitude.EndsWith("N") Or m_title.Latitude.EndsWith("n") Then
                            Me.cobWd.Text = "N"
                        Else
                            Me.cobWd.Text = "S"
                        End If


                        Me.m_title.Longitude = StringHandle.GetString(strline, 2)

                        Me.txtLatitude.Text = m_title.Longitude.Remove(m_title.Longitude.Length - 1)
                        If m_title.Longitude.EndsWith("e") Or m_title.Longitude.EndsWith("E") Then
                            Me.cobJd.Text = "E"
                        Else
                            Me.cobJd.Text = "W"
                        End If

                        Me.m_title.Ua_Id = StringHandle.GetString(strline, 4)
                        Me.txtUA_ID.Text = Me.m_title.Ua_Id


                        Me.m_title.Sf_Id = StringHandle.GetString(strline, 6)

                        Me.txtSF_ID.Text = Me.m_title.Sf_Id


                        Me.m_title.Os_Id = StringHandle.GetString(strline, 8)
                        'OS_ID = StringHandle.GetString(strline, 8)


                        Me.m_title.Version = StringHandle.GetString(strline, 10)
                        Me.txtVERSION.Text = Me.m_title.Version

                    ElseIf a > 1 Then
                        ReDim Preserve m_ArrConcourse.ArrGroundDataCommunication(p)
                        m_ArrConcourse.ArrGroundDataCommunication(p) = New GroundDataCommunication
                        If StringHandle.GetString(strline, 1).Trim().Length > 2 Then
                            Me.m_ArrConcourse.ArrGroundDataCommunication(p).Year = CInt(StringHandle.GetString(strline, 1))
                        Else
                            If StringHandle.GetString(strline, 1) >= 50 Then
                                Me.m_ArrConcourse.ArrGroundDataCommunication(p).Year = "19" & CInt(StringHandle.GetString(strline, 1))
                            ElseIf StringHandle.GetString(strline, 1) >= 10 Then
                                Me.m_ArrConcourse.ArrGroundDataCommunication(p).Year = "20" & CInt(StringHandle.GetString(strline, 1))
                            ElseIf StringHandle.GetString(strline, 1) >= 0 And StringHandle.GetString(strline, 1) <= 9 Then
                                Me.m_ArrConcourse.ArrGroundDataCommunication(p).Year = "200" & CInt(StringHandle.GetString(strline, 1))
                            End If
                        End If


                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).Month = StringHandle.GetString(strline, 2)
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).Day = StringHandle.GetString(strline, 3)
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).CountDay = StringHandle.GetString(strline, 4)
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).Time = StringHandle.GetString(strline, 5)



                        f_HeatEnergy = Mid(strline, 16, 7)
                        f_TerraRubVelocity = Mid(strline, 23, 7)
                        f_ConvectionVelocityScale = Mid(strline, 30, 7)
                        f_LadderTemperature = Mid(strline, 37, 7)
                        f_ConvectionBoundaryHeight = Mid(strline, 44, 6)

                        f_MachineBoundaryHeight = Mid(strline, 50, 6)
                        f_MoniLong = Mid(strline, 56, 9)
                        f_TerraCrassitude = Mid(strline, 65, 7)
                        f_TerraBowen = Mid(strline, 72, 7)
                        f_TerraAlbedo = Mid(strline, 79, 7)

                        f_WindSpeed = Mid(strline, 86, 8)
                        f_WindVane = Mid(strline, 94, 6)
                        f_WindHeight = Mid(strline, 100, 7)
                        f_Lapse_Rate = Mid(strline, 107, 7)
                        f_TemperatureScaleHeight = Mid(strline, 114, 7)

                        f_DropWaterType = Mid(strline, 121, 6)
                        f_DropWaterQuantity = Mid(strline, 127, 7)
                        f_ComparativelyHumidity = Mid(strline, 134, 7)
                        f_TerraPa = Mid(strline, 141, 7)
                        f_LowCloudCover = Mid(strline, 148, 6)


                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).HeatEnergy = CDbl(f_HeatEnergy.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraRubVelocity = CDbl(f_TerraRubVelocity.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).ConvectionVelocityScale = CDbl(f_ConvectionVelocityScale.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).LadderTemperature = CDbl(f_LadderTemperature.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).ConvectionBoundaryHeight = CDbl(f_ConvectionBoundaryHeight.Trim())

                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).MachineBoundaryHeight = CDbl(f_MachineBoundaryHeight.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).MoniLong = CDbl(f_MoniLong.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraCrassitude = CDbl(f_TerraCrassitude.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraBowen = CDbl(f_TerraBowen.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraAlbedo = CDbl(f_TerraAlbedo.Trim())

                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).WindSpeed = CDbl(f_WindSpeed.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).WindVane = CDbl(f_WindVane.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).WindHeight = CDbl(f_WindHeight.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).Lapse_Rate = CDbl(f_Lapse_Rate.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).TemperatureScaleHeight = CDbl(f_TemperatureScaleHeight.Trim())

                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).DropWaterType = CDbl(f_DropWaterType.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).DropWaterQuantity = CDbl(f_DropWaterQuantity.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).ComparativelyHumidity = CDbl(f_ComparativelyHumidity.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraPa = CDbl(f_TerraPa.Trim())
                        Me.m_ArrConcourse.ArrGroundDataCommunication(p).LowCloudCover = CDbl(f_LowCloudCover.Trim())

                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).HeatEnergy = StringHandle.GetString(strline, 6)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraRubVelocity = StringHandle.GetString(strline, 7)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).ConvectionVelocityScale = StringHandle.GetString(strline, 8)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).LadderTemperature = StringHandle.GetString(strline, 9)


                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).ConvectionBoundaryHeight = StringHandle.GetString(strline, 10)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).MachineBoundaryHeight = StringHandle.GetString(strline, 11)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).MoniLong = StringHandle.GetString(strline, 12)


                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraCrassitude = StringHandle.GetString(strline, 13)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraBowen = StringHandle.GetString(strline, 14)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraAlbedo = StringHandle.GetString(strline, 15)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).WindSpeed = StringHandle.GetString(strline, 16)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).WindVane = StringHandle.GetString(strline, 17)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).WindHeight = StringHandle.GetString(strline, 18)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).Lapse_Rate = StringHandle.GetString(strline, 19)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).TemperatureScaleHeight = StringHandle.GetString(strline, 20)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).DropWaterType = StringHandle.GetString(strline, 21)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).DropWaterQuantity = StringHandle.GetString(strline, 22)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).ComparativelyHumidity = StringHandle.GetString(strline, 23)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).TerraPa = StringHandle.GetString(strline, 24)
                        'Me.m_ArrConcourse.ArrGroundDataCommunication(p).LowCloudCover = StringHandle.GetString(strline, 25)
                        p = p + 1
                    End If

                Loop
                FileClose(1)
                If msgerror = True Then
                    ShowFlexData()
                End If

            End If
        End If
    End Sub

    Private Sub btnSaveFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveFile.Click
        Dim saveFileDialog1 As New SaveFileDialog()

        saveFileDialog1.Filter = "地面气象数据文件(*.SFC)|*.SFC"
        saveFileDialog1.FilterIndex = 2
        saveFileDialog1.RestoreDirectory = True
        saveFileDialog1.InitialDirectory = Application.ExecutablePath
        saveFileDialog1.OverwritePrompt = True
        Dim sw As StreamWriter ' = New StreamWriter("C:\a.txt")
        Dim cc As String = ""
        Dim title As String = ""
        Dim year As String = ""
        Dim UA_ID As String = "UA_ID:"
        Dim SF_ID As String = "SF_ID:"
        Dim OS_ID As String = "OS_ID:"
        Dim VERSION As String = "VERSION:"
        If txtUA_ID.Text = Nothing Or txtUA_ID.Text.Trim() = "" Then
            MessageBox.Show("探空站台号不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If txtSF_ID.Text = Nothing Or txtSF_ID.Text.Trim() = "" Then
            MessageBox.Show("地面站台号不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If

        If txtVERSION.Text = Nothing Or txtVERSION.Text.Trim() = "" Then
            MessageBox.Show("地面站台号不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If


        If txtLatitude.Text = Nothing Or txtLatitude.Text.Trim() = "" Then
            MessageBox.Show("纬度不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If txtLongitude.Text = Nothing Or txtLongitude.Text.Trim() = "" Then
            MessageBox.Show("经度不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If Me.m_OpenFile = False Then
            MessageBox.Show("没有导入任何数据，没有数据不能保存！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        Else
            title = Me.m_title.Latitude.ToString.PadLeft(10) & Me.m_title.Longitude.ToString.PadLeft(10) & UA_ID.ToString.PadLeft(16) & Me.m_title.Ua_Id.ToString.PadLeft(9) & SF_ID.ToString.PadLeft(8) & Me.m_title.Sf_Id.ToString.PadLeft(9) & OS_ID.ToString.PadLeft(8) & Me.m_title.Os_Id.ToString.PadLeft(9) & VERSION.ToString.PadLeft(13) & Me.m_title.Version.ToString.PadLeft(6)

            If saveFileDialog1.ShowDialog() = DialogResult.OK Then

                sw = New StreamWriter(saveFileDialog1.FileName)
                sw.WriteLine(title)
                For i As Double = 0 To Me.m_ArrConcourse.ArrGroundDataCommunication.Length - 1
                    cc = ""
                    year = Me.m_ArrConcourse.ArrGroundDataCommunication(i).Year
                    cc += Mid(year, 3, 2)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).Month.ToString.PadLeft(3)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).Day.ToString.PadLeft(3)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).CountDay.ToString.PadLeft(4)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).Time.ToString.PadLeft(3)

                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).HeatEnergy.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraRubVelocity.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).ConvectionVelocityScale.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).LadderTemperature.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).ConvectionBoundaryHeight.ToString.PadLeft(6)

                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).MachineBoundaryHeight.ToString.PadLeft(6)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).MoniLong.ToString.PadLeft(9)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraCrassitude.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraBowen.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraAlbedo.ToString.PadLeft(7)

                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindSpeed.ToString.PadLeft(8)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindVane.ToString.PadLeft(6)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).WindHeight.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).Lapse_Rate.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).TemperatureScaleHeight.ToString.PadLeft(7)

                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).DropWaterType.ToString.PadLeft(6)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).DropWaterQuantity.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).ComparativelyHumidity.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).TerraPa.ToString.PadLeft(7)
                    cc += Me.m_ArrConcourse.ArrGroundDataCommunication(i).LowCloudCover.ToString.PadLeft(6) ' & vbCrLf
                    sw.WriteLine(cc)

                Next
                'PrintLine(1, cc)
                'FileClose(1)

                sw.Close()
                sw.Dispose()
            End If
        End If

    End Sub

    Private Sub txtUA_ID_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtUA_ID.Validating
        Me.m_title.Ua_Id = Me.txtUA_ID.Text
    End Sub

    Private Sub txtSF_ID_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtSF_ID.Validating
        Me.m_title.Sf_Id = Me.txtSF_ID.Text
    End Sub

    Private Sub txtVERSION_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtVERSION.Validating
        Me.m_title.Version = Me.txtVERSION.Text
    End Sub

    Private Sub txtLongitude_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtLongitude.Validating
        Try
            If Me.txtLongitude.Text = "" Or Me.txtLongitude.Text.Trim() = "" Then
                Exit Sub
            ElseIf CDbl(Me.txtLongitude.Text) < 1 Then

            End If

        Catch ex As Exception
            Me.txtLongitude.Text = ""
            MessageBox.Show("请正确输入，数字！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End Try
        Me.m_title.Longitude = txtLongitude.Text & cobJd.Text
    End Sub

    Private Sub txtLatitude_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtLatitude.Validating
        Try
            If Me.txtLatitude.Text = "" Or Me.txtLatitude.Text.Trim() = "" Then

                Exit Sub
            ElseIf CDbl(Me.txtLatitude.Text) < 1 Then

            End If

        Catch ex As Exception
            Me.txtLatitude.Text = ""
            MessageBox.Show("请正确输入，数字！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End Try
        Me.m_title.Latitude = txtLatitude.Text & cobWd.Text
    End Sub

    Private Sub cobJd_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cobJd.Validating
        Me.m_title.Longitude = txtLongitude.Text & cobJd.Text
    End Sub

    Private Sub cobWd_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cobWd.Validating
        Me.m_title.Latitude = txtLatitude.Text & cobWd.Text
    End Sub
End Class
